package org.spring.spring.proxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.*;

/**
 * @projectName: sky-springboot
 * @package: org.spring.spring.proxy
 * @className: CircularDependencyProxy
 * @author: zhl
 * @description: 循环依赖代理类
 * @date: 2024/3/20 10:08
 * @version: 1.0
 */
public class CircularDependencyProxy implements MethodInterceptor {

    /** 被代理对象（bean的普通对象） **/
    private Object target;

    public CircularDependencyProxy(Object target) {
        this.target = target;
    }

    /**
     * @param o: 代理对象
     * @param method: 被代理方法
     * @param params: 方法入参
     * @param methodProxy: CGLIB方法
     **/
    @Override
    public Object intercept(Object o, Method method, Object[] params, MethodProxy methodProxy) throws Throwable {
        System.out.println("【增强方法】代理对象正在执行的方法：" + method.getName());
        Object result = methodProxy.invokeSuper(o, params);
        return result;
    }
}
